
<div class="box-header with-border">
    <h3 class="box-title">返利配置</h3>
    <!-- /.box-tools -->
</div>

<div class="box" style="border:0px;">
    <div class="box-body table-responsive">
        <table class="table table-striped table-hover">
            <tbody id="row_rebate_ratio_data">
            </tbody>
        </table>
    </div>
    <!-- /.box-body -->
    <div class="overlay hidden">
        <i class="fa fa-refresh fa-spin"></i>
    </div>
</div>

<script>

    loadRebateRatioData();
    //加载数据
    function loadRebateRatioData() {
        showLoad();
        $.ajax({
            type : "get",
            url : '__ADMIN__/RebateRatio/tolist',
            dataType:"json",
            success : function(msg) {
                hideLoad();
                showRebateRatioData(msg);
            }
        });
    }

    //数据拼装
    function showRebateRatioData(msg) {
        var rebate_layer = '__REBATELAYER__';
        var rebate_layer_alias = '__REBATELAYERALIAS__';
        if (null == rebate_layer_alias && rebate_layer_alias == "") {
            rebate_layer_alias = "";
            for (var i=0; i<rebate_layer.length; i++) {
                if (i>0) {
                    rebate_layer_alias += ",";
                }
                rebate_layer_alias += "第"+(i+1)+"层"
            }
        }

        var content = '';
        //datatable head
        content += '<tr>';
        content += '<th style="width:35px;">#</th>';
        content += '<th>货币</th>';
        content += '<th>返利比例(%)</th>';
        /*for (var i=0; i<rebate_layer; i++) {
            content += '<th>第'+(i+1)+'层返利比例</th>';
        }*/
        content += '<th style="width:130px;">操作</th>';
        content += '</tr>';

        //datatable data
        for (var i = 0; i < msg.data.length; i++) {
            content += '<tr>';
            content += '<td>' + (i+1) + '</td>';
            content += '<td>' + msg.data[i].show_name + '</td>';
            content += '<td>' + msg.data[i].rebate_ratio + '</td>';

            content += '<td>';
            content += '<span class="label label-primary" style="cursor:pointer;margin-right:3px;" onclick="edit_rebate_ratio_data(\'' + msg.data[i].id + '\');">修改</span>';
            content += '</td>';
            content += '</tr>';
        }
        $('#row_rebate_ratio_data').html(content);
    }

    function edit_rebate_ratio_data(play_type) {
        $.ajax({
            type : "post",
            url : '__ADMIN__/RebateRatio/get_data',
            dataType:"json",
            data: {
                play_type : play_type
            },
            success : function(msg) {
                open_rebate_ratio_win_from("修改配置", msg.data, play_type);
            }
        });
    }

    function open_rebate_ratio_win_from(title, rebate, play_type) {
        var html = '<form id="daer_rebate_ratio_from" onsubmit="return false">';
        html += '<input type="hidden" class="form-control" name="play_type" id="play_type" value="'+play_type+'">';
        for (var i=0; i<rebate.length; i++) {
            html += '<div class="form-group">';
            html += '<label for="rebate_ratio">第'+rebate[i].rebate_level+'经纪人</label>';
            html += '<input type="text" class="form-control" name="rebate_ratio[]" id="rebate_ratio" value="'+rebate[i].rebate_ratio+'" placeholder="返利比例">';
            html += '</div>';
        }
        html += '</form>';
        var load = null;
        layer.open({
            anim:3,
            title: title,
            area: '500px',
            content: html,
            btn: ['保存'],
            yes: function(index, layero){
                //按钮【按钮一】的回调
                var d = $('#daer_rebate_ratio_from').serializeArray();
                $.ajax({
                    type:"POST",
                    url : '__ADMIN__/RebateRatio/addoreditbigtradeconfig',
                    dataType:"json",
                    data:d,
                    beforeSend:function () {
                        load = layer.load();
                    },
                    success:function(msg) {
                        loadRebateRatioData();
                        layer.close(load);
                        layer.alert(msg.msg);
                        if (msg.code == 0)
                            layer.close(index);
                    }
                });
            }
        });
    }
</script>